class Solution {
public:
    vector<string> res;
    void gen(string str, int left, int right)
    {
        if(left==0 && right==0)
        {
            res.push_back(str);
            return;
        }

        if(left == right)
            gen(str+"(", left-1, right);
        else
        {
            if(left > 0)
                gen(str+"(", left-1, right);
            gen(str+")", left, right-1);
        }

        return;
    }
    vector<string> generateParenthesis(int n) {
        gen("", n, n);
        return res;
    }
};